#pragma once

#include <pthread.h>

class Mutex 
{
public:
    Mutex(pthread_mutex_t* lock)
        : _lock(lock)
        {}
    
    void Lock()
    {
        pthread_mutex_lock(_lock);
    }

    void Unlock()
    {
        pthread_mutex_unlock(_lock);
    }
    
    ~Mutex()
    {}

private:
    pthread_mutex_t* _lock; 
};

class LockGuard     // RAII class for locking and unlocking a mutex---需要传入指针
{
public:
    LockGuard(pthread_mutex_t* mutex)
        : _mutex(mutex)
    {
        _mutex.Lock();
    }

    ~LockGuard()
    {
        _mutex.Unlock();
    }

private:
    Mutex _mutex;
};